package br.com.treinamento.gestaoExperienciaProfissional.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.NoResultException;
import javax.persistence.Query;

import br.com.treinamento.gestaoExperienciaProfissional.model.Pessoa;


public class PessoaDAO extends GenericDAO<Pessoa> implements Serializable {

	private static final long serialVersionUID = -5828854152854362939L;
	
	public List<Pessoa> buscarPorEmail(String email) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT p ");
		sb.append("FROM Pessoa p ");
		sb.append("JOIN FETCH p.emails e ");
		sb.append("WHERE e.email = :email");

		Query query = criarQuery(sb.toString());
		query.setParameter("email", email);

		try {
			return (List<Pessoa>) query.getResultList();
		} catch (NoResultException e) {
			return null;
		}
	}

}
